const util= require('../../utils/util.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    token: '',
    show: false,//控制下拉列表的显示隐藏，false隐藏、true显示
    selectData: ['下拉列表', '首页', '告警', '摄像头', '服务器', '智慧功底'],//下拉列表的数据
    index: 0,//选择的下拉列表下标
    warntotal: '',
    warnList: [],
    warnDate: ''
  },
  // 点击下拉显示框
  selectTap() {
    this.setData({
      show: !this.data.show
    });
  },
  // 点击下拉列表
  optionTap(e) {
    let Index = e.currentTarget.dataset.index;//获取点击的下拉列表的下标
    this.setData({
      index: Index,
      show: !this.data.show
    });
  },
  jumpHome: function () {
    wx.redirectTo({
      url: '../home/home',
    })
  },
  jumpWarn: function () {
    wx.redirectTo({
      url: 'warn',
    })
  },
  jumpCamera: function () {
    wx.redirectTo({
      url: '../camera/camera',
    })
  },
  jumpServer: function () {
    wx.redirectTo({
      url: '../server/server',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    let that = this;
    wx.getStorage({
      key: 'token',
      success: function (res) {
        that.setData({
          token: res.data
        })

        let header = {
          'context-type': 'application/json',
          'UserToken': that.data.token,
          'Cookie': wx.getStorageSync("sessionid")
        }
        wx.request({
          url: 'https://www.2edge.cn/rest/alarm/queryList',
          method: 'post',
          header: header,
          data: {
            "pageNum": '',
            "pageSise": '',
            "conditions": [{}, {}]
          },
          success: function (res) {
            var resArr = res.data.data.records;
            that.setData({
              warntotal: res.data.data.total,
              warnList: resArr,
              warnDate: util.formatTime(new Date())
            })
          }
        })
      }
    })
  }
})